<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="Linker员工信息ID">
          <a-input placeholder="请输入Linker员工信息ID" v-decorator="['authUserId', validatorRules.authUserId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['displayname', validatorRules.displayname ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="姓名">
          <a-input placeholder="请输入姓名" v-decorator="['name', validatorRules.name ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="linker密码">
          <a-input placeholder="请输入linker密码" v-decorator="['password', validatorRules.password ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="性别">
          <a-input placeholder="请输入性别" v-decorator="['genderid', validatorRules.genderid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="出生日期">
          <a-input placeholder="请输入出生日期" v-decorator="['birthday', validatorRules.birthday ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最高学历">
          <a-input placeholder="请输入最高学历" v-decorator="['highdegree', validatorRules.highdegree ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="毕业学校">
          <a-input placeholder="请输入毕业学校" v-decorator="['school', validatorRules.school ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="现居住地">
          <a-input placeholder="请输入现居住地" v-decorator="['adress', validatorRules.adress ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="手机">
          <a-input placeholder="请输入手机" v-decorator="['tel', validatorRules.tel ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="微信">
          <a-input placeholder="请输入微信" v-decorator="['wechat', validatorRules.wechat ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="入职日期">
          <a-input placeholder="请输入入职日期" v-decorator="['joineddate', validatorRules.joineddate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="职务">
          <a-input placeholder="请输入职务" v-decorator="['position', validatorRules.position ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="在职状态">
          <a-input placeholder="请输入在职状态" v-decorator="['workstatusid', validatorRules.workstatusid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯省">
          <a-input placeholder="请输入籍贯省" v-decorator="['provinceid', validatorRules.provinceid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯市">
          <a-input placeholder="请输入籍贯市" v-decorator="['cityid', validatorRules.cityid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯区/县">
          <a-input placeholder="请输入籍贯区/县" v-decorator="['districtid', validatorRules.districtid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="婚育情况">
          <a-input placeholder="请输入婚育情况" v-decorator="['marriagebearing', validatorRules.marriagebearing ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="紧急联系人">
          <a-input placeholder="请输入紧急联系人" v-decorator="['emergencycontact', validatorRules.emergencycontact ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="紧急联系人手机">
          <a-input placeholder="请输入紧急联系人手机" v-decorator="['contacttel', validatorRules.contacttel ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否开通Linker账号">
          <a-input placeholder="请输入是否开通Linker账号" v-decorator="['isuser', validatorRules.isuser ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新日期">
          <a-input placeholder="请输入最近更新日期" v-decorator="['ts', validatorRules.ts ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-input placeholder="请输入状态" v-decorator="['datastatus', validatorRules.datastatus ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['gender', validatorRules.gender ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近修改人">
          <a-input placeholder="请输入最近修改人" v-decorator="['updatebyid', validatorRules.updatebyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['cellphone', validatorRules.cellphone ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['ct', validatorRules.ct ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "AuthUserModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        authUserId:{rules: [{ required: true, message: '请输入Linker员工信息ID!' }]},
        displayname:{rules: [{ required: true, message: '请输入!' }]},
        name:{rules: [{ required: true, message: '请输入姓名!' }]},
        password:{rules: [{ required: true, message: '请输入linker密码!' }]},
        genderid:{rules: [{ required: true, message: '请输入性别!' }]},
        birthday:{rules: [{ required: true, message: '请输入出生日期!' }]},
        highdegree:{rules: [{ required: true, message: '请输入最高学历!' }]},
        school:{rules: [{ required: true, message: '请输入毕业学校!' }]},
        adress:{rules: [{ required: true, message: '请输入现居住地!' }]},
        tel:{rules: [{ required: true, message: '请输入手机!' }]},
        wechat:{rules: [{ required: true, message: '请输入微信!' }]},
        joineddate:{rules: [{ required: true, message: '请输入入职日期!' }]},
        position:{rules: [{ required: true, message: '请输入职务!' }]},
        workstatusid:{rules: [{ required: true, message: '请输入在职状态!' }]},
        provinceid:{rules: [{ required: true, message: '请输入籍贯省!' }]},
        cityid:{rules: [{ required: true, message: '请输入籍贯市!' }]},
        districtid:{rules: [{ required: true, message: '请输入籍贯区/县!' }]},
        marriagebearing:{rules: [{ required: true, message: '请输入婚育情况!' }]},
        emergencycontact:{rules: [{ required: true, message: '请输入紧急联系人!' }]},
        contacttel:{rules: [{ required: true, message: '请输入紧急联系人手机!' }]},
        isuser:{rules: [{ required: true, message: '请输入是否开通Linker账号!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        gender:{rules: [{ required: true, message: '请输入!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近修改人!' }]},
        cellphone:{rules: [{ required: true, message: '请输入!' }]},
        ct:{rules: [{ required: true, message: '请输入!' }]},
        },
        url: {
          add: "/robot/authUser/add",
          edit: "/robot/authUser/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'authUserId','displayname','name','password','genderid','birthday','highdegree','school','adress','tel','wechat','joineddate','position','workstatusid','provinceid','cityid','districtid','marriagebearing','emergencycontact','contacttel','isuser','ts','datastatus','gender','updatebyid','cellphone','ct'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>